package com.xxmw.transaction.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxmw.transaction.common.entity.R;
import com.xxmw.transaction.common.utils.Assert;
import com.xxmw.transaction.model.app.VipPrice;
import com.xxmw.transaction.service.app.IVipPriceService;
import com.xxmw.transaction.service.app.IVipRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * Vip价格 controller
 */
@Slf4j
@RestController
@RequestMapping("/admin/vipPrice")
public class AdminVipPriceController {

    @Autowired
    private IVipPriceService vipPriceService;


    @GetMapping("list")
    public R list (@RequestParam(required = false, defaultValue = "1") Integer page,
                   @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        LambdaQueryWrapper<VipPrice> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(VipPrice::getId);
        IPage<VipPrice> result = vipPriceService.page(new Page<>(page, pageSize), wrapper);
        return R.ok(result);
    }

    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(VipPrice vipPrice) {
        if (Assert.isNotNullOrEmpty(vipPrice.getId())) {
            vipPriceService.updateById(vipPrice);
        } else {
            vipPriceService.save(vipPrice);
        }
        return R.ok();
    }

    @GetMapping("delete/{id}")
    public R delete(@PathVariable Integer id) {
        vipPriceService.removeById(id);
        return R.ok();
    }

}
